package com.atom.common.util;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.atom.common.CommonConstant;
import com.atom.common.exception.AvensIllegalArgumentException;

public class TicketUtil {

  private static Logger logger = Logger.getLogger(TicketUtil.class); 

  private static final boolean PROXY_MODE = GlobalConfigReader.getBooleanValue(CommonConstant.PROXY_MODE);

  public static String appendTicket(StringBuffer url, HttpSession session) {
    logger.info("PROXY_MODE : " + PROXY_MODE);
    if (PROXY_MODE) {
      String proxyTicket = getTicket(url.toString(), session);
      if (proxyTicket == null) {
        throw new AvensIllegalArgumentException("proxyTicket is null");
      }
      url.append("?ticket=");
      url.append(proxyTicket);
      return url.toString();
    } else {
      return url.toString();
    }
  }

  private static String getTicket(String url, HttpSession session) {
//    if (url == null || session == null) {
//      throw new AvensIllegalArgumentException("url or session is null");
//    }
//
//    Assertion assertion = (Assertion) session.getAttribute("_const_cas_assertion_");
//    String pt = assertion.getPrincipal().getProxyTicketFor(url);
//
//    return pt;
	  return "";
  }

}
